<?php
session_start() ;
if(!isset($_SESSION["login"]) || $_SESSION["login"] == "")
{   
  header("Location: index.php?error=4") ;
}?>

<html>
<head>
<title>Administration</title>
 <link rel="stylesheet" type="text/css" href="style.css" >  
</head>

<body>
<?php require("menu.php");
require("fonctions.php");
$code=$_GET["error"];
$codesap=$_GET["codesap"];
$action = $_GET["action"];
$contact = $_GET["contact"];
?>
<br>
<?php echo error_message($code);?>
<?php 
$sql="select * from distributeurs where codesap='$codesap'";
$res = mysql_query($sql);
$r  = mysql_fetch_object($res);
$t_man = explode (",",getManagernameById(getIdManagerByDis($r->id)));
?>

<table  width="250" >
<tr>
	<td class="tab_dis_head">FICHE ETABLISSEMENT</td>
</tr>
</table>
<label>CODE SIGA :  <?php echo $codesap;?> &nbsp;&nbsp;&nbsp;&ndash; <?php echo $r->nom; ?></label>
<label>ZONE :  <?php echo $valz = getZoneNameById($r->id_zone);?></label>
<label>RESEAU : <?php echo $valr =  getReseauNameById($r->id_reseau)?></label>
<label>GROUPE :  <?php echo $r->groupe;?></label>
<br>
<form action="controler.php?action=modif_dis" method="post">
<input type="hidden" name="id_man" value="<?php echo $val=getIdManagerByDis($r->id);?>">
<input type="hidden" name="id_dis" value="<?php echo $r->id;?>">
<input type="hidden" name="id_distrib" value="<?php echo $r->id;?>">
<input type="hidden" name="codesap" value="<?php echo $codesap;?>">
<table  width="500" >
<tr>
	<td class="tab_dis_head">Manager Renault Trucks</td>
</tr>
<tr>
<td>Nom </td>
	<td><input type="text" size="50" name="nom" value="<?php echo "$t_man[0]"; ?>"></td>
</tr>
<tr>
<td>Pr&eacute;nom </td>
	<td><input type="text" size="50" name="prenom" value="<?php echo "$t_man[1] "; ?>"></td>
</tr>
<tr>
<td>Adresse mail </td>
	<td><input type="text" size="50" name="email" value="<?php echo "$t_man[2]"; ?>"></td>
</tr>
<tr>
<td>Fonction</td>
	<td><input type="text" size="50" name="fonction" value="<?php echo "$t_man[3]"; ?>"></td>
</tr>

</table>
<br>
<table  width="350" >
<tr>
	<td class="tab_dis_head" colspan="2">LISTE DES CONTACTS</td>
</tr>
</table>
<table  class="tab_dis_contact">
<tr>
<td class="tab_dis_head">ID</td>
<td class="tab_dis_head">NOM</td>
<td class="tab_dis_head">PRENOM</td>
<td class="tab_dis_head">EMAIL</td>
<td class="tab_dis_head">FONCTION</td>
<td class="tab_dis_head">ACTION</td>
</tr>
<?php $sql2="select * from contacts where id_distrib=$r->id";
$res2 = mysql_query($sql2);	
$i=1;
while($r2 = mysql_fetch_object($res2)){

	$nom= "$r2->nom $r2->prenom";

?>
<tr>
<td class="tab_dis_data"><?php echo $r2->id;?></td>
<td class="tab_dis_data"><?php echo $r2->nom;?></td>
<td class="tab_dis_data"><?php echo $r2->prenom;?></td>
<td class="tab_dis_data"><?php echo $r2->email;?></td>
<td class="tab_dis_data"><?php //echo $r2->fonction;?></td>
<td class="tab_dis_data"><a href="lv_details.php?action=modif_dis&contact=mod_contact&cur=3&codesap=<?php echo $codesap;?>&id=<?php echo $r2->id;?>#bas">Modifier</a> / <a href="controler.php?action=sup_contact&id=<?php echo $r2->id;?>&codesap=<?php echo $codesap;?>">Supprimer</a> / 
	</td>
</tr>
<?php $i++;}?>

</table>
<?php if($contact!="add_contact"){?>

<table>
<tr>
<td colspan="2" align=center><a class="bouton" href="lv_details.php?action=modif_dis&contact=add_contact&cur=3&codesap=<?php echo $codesap;?>#bas">Ajouter un nouveau contact</a> </td>
</tr>
</table>
<?php }?>

<br>
<a name="bas"></a>
<?php if($contact=="add_contact"){?>
<input type="hidden" name="val_contact" value="<?php echo $contact;?>">
<table>
<tr>
	<td class="tab_dis_head" colspan="2">AJOUTER UN CONTACT</td>
</tr>
</table>
<table>
<tr>
<td>Nom </td><td><input type="text" size="50" name="nom_contact"  ></td>
</tr>
<tr>
<td>Pr&eacute;nom</td><td><input type="text" size="50" name="prenom_contact"  ></td>
</tr>
<tr>
<td>Email</td><td><input type="text" size="50" name="email_contact" ></td>
</tr>
<tr>
<td>Fonction</td><td><input type="text" size="50" name="fonction_contact" ></td>
</tr>
</table>
<?php }?>
<a name="bas"></a>
<?php if($contact=="mod_contact"){
$id=$_GET["id"];
$s3 = "select * from contacts where id=$id";
$res3 = mysql_query($s3);

$r3 = mysql_fetch_object($res3);

	?>
<input type="hidden" name="val_contact" value="<?php echo $contact;?>">	
<input type="hidden" name="id_contact" value="<?php echo $id;?>">	
<table>
<tr>
	<td class="tab_dis_head" colspan="2">MODIFIER UN CONTACT</td>
</tr>
</table>
<table>
<tr>
<td>Nom </td><td><input type="text" size="50" name="nom_contact"  value="<?php echo $r3->nom;?>" ></td>
</tr>
<tr>
<td>Pr&eacute;nom</td><td><input type="text" size="50" name="prenom_contact"  value="<?php echo $r3->prenom;?>"></td>
</tr>
<tr>
<td>Email</td><td><input type="text" size="50" name="email_contact" value="<?php echo $r3->email;?>"></td>
</tr>
<tr>
<td>Fonction</td><td>
<?php //echo $r3->fonction;?>
<!--<select name="fonction_contact" >
<option value=""></option>
<option value="Directeur">Directeur</option>
<option value="Responsable APV">Responsable APV</option>
<option value="Chef Atelier">Chef Atelier</option>
<option value="Chef Magasin">Chef Magasin</option>
<option value="Chef Equipe">Chef Equipe</option>
<option value="R&eacute;ceptionnaire">R&eacute;ceptionnaire</option>
<option value="Autre">Autre</option>
</select>-->

</td>
</tr>
</table>
<?php }?>
<table>
<tr>
<td colspan="2" align=center><input type="submit" value="Valider la saisie !"> </td>
</tr>
</table>
</form>
</body>

</html>
